//
//  OrderLogisticsTableViewCell.m
//  much
//
//  Created by Believer Just on 2019/1/11.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "OrderLogisticsTableViewCell.h"

@interface OrderLogisticsTableViewCell ()

@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * timeLabel;
@property (nonatomic, strong) UIImageView *titleImageView;
@property (nonatomic, weak) UILabel * arrowLabel;

@end

@implementation OrderLogisticsTableViewCell

+ (instancetype)initTableView:(UITableView *)tableView {
    OrderLogisticsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OrderLogisticsTableViewCell class])];
    if (!cell) {
        cell = [[OrderLogisticsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([OrderLogisticsTableViewCell class])];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];;
    }
    return self;
}

- (void)setArrowTitleHidden:(BOOL)hidden {
    NSString *str = [ @"更多包裹 " stringByAppendingString:ARROW_RIGHT];
    if (hidden) {
        str = [ @" " stringByAppendingString:ARROW_RIGHT];
    }
    self.arrowLabel.text = str;
}

- (void)setModel:(MyOrderLogisticsTracksModel *)model {
    _model = model;
    
    self.titleImageView.backgroundColor = [UIColor clearColor];
    self.nameLabel.text = model.context;
    self.timeLabel.text = model.ftime;
}

- (UIImageView *)titleImageView {
    if (!_titleImageView) {
        _titleImageView = [UIImageView new];
        [_titleImageView setImage:[UIImage imageNamed:@"order_logistics"]];
        [self.contentView addSubview:_titleImageView];
        [_titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(18);
            make.height.mas_equalTo(@15);
            make.width.mas_equalTo(@15);
            make.centerY.equalTo(self.contentView.mas_centerY);
        }];
    }
    return _titleImageView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        UILabel * arrowLabel = [UILabel new];
        _arrowLabel = arrowLabel;
        arrowLabel.textColor = HEXCOLOR(0x303030);
        arrowLabel.font = ICONFONT(16);
        arrowLabel.text = [@"更多包裹 " stringByAppendingString:ARROW_RIGHT];
        // 同label不同字体大小
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:arrowLabel.text];
        NSRange range = [arrowLabel.text rangeOfString:@" "];
        NSDictionary *rangMoneydic = @{NSForegroundColorAttributeName:Color34, NSFontAttributeName:APPFONT(12)};
        NSDictionary *rangAfterdic = @{NSForegroundColorAttributeName:Color34, NSFontAttributeName:ICONFONT(16)};
        [attrString addAttributes:rangMoneydic range:NSMakeRange(0, range.location)];
        [attrString addAttributes:rangAfterdic range:NSMakeRange(range.location, arrowLabel.text.length - range.location)];
        [arrowLabel setAttributedText:attrString];
        
        [self.contentView addSubview:arrowLabel];
        [arrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).with.offset(-15);
            make.top.bottom.equalTo(self.contentView);
        }];
        
        _nameLabel = [UILabel new];
        _nameLabel.font = APPFONT(14);
        _nameLabel.textColor = Color175030;
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleImageView.mas_right).with.offset(10);
            make.right.equalTo(self.contentView).offset(-100);
            make.top.mas_equalTo(@10);
        }];
        
    }
    return _nameLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel new];
        _timeLabel.font = APPFONT(12);
        _timeLabel.numberOfLines = 2;
        _timeLabel.textColor = HEXCOLOR(0x8a8a8a);
        [self.contentView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.nameLabel.mas_bottom).with.offset(5);
            make.height.mas_lessThanOrEqualTo(@26);
            make.left.equalTo(self.nameLabel);
            make.right.equalTo(self.contentView).with.offset(-10);
        }];
    }
    return _timeLabel;
}
@end
